package auction

class IntegrationTests extends GroovyTestCase {

    void testNonUniqueEmailAddress()
    {
        Customer customer1 = new Customer(password: "12345678", emailAddress: "brian@gmail.com")
        Customer customer2 = new Customer(password: "87654321", emailAddress: "brian@gmail.com")

        assert !customer2.validate() : "Two customers with same email address valid."
    }

    void testBidsSavedWhenListingSaved()
    {
        // create a listing
        Listing newListing = new Listing(name: "hammer", startingBid: "20.00", endDate: new Date().next())

        // create a bid
        String bidAmount = "20.00"
        Date dateOfBid = new Date()
        Customer customer = new Customer(password: "12345678", emailAddress: "brian@gmail.com")
        Bid bid = new Bid(amount: bidAmount, bidDate: dateOfBid, listing: newListing, bidder: customer)

        // add bid to listing
        newListing.bids.add(bid)

        // save the listing
        newListing.save()

        // make sure the new bid exists and has a matching listing id
        assert Bid.findById(bid.id).listing.id == listing.id : "The listing's bid does not exist or does not have matching listing id."
    }
}
